-module(event_handler).
-compile(export_all).

make(Name) ->
	register(Name, spawn(fun() -> my_handler(fun no_op/1) end)).
	
add_handler(Name, Fun) -> Name ! {add, Fun}.

event(Name, X) -> Name ! {event, X}.

my_handler(Fun) ->
	receive
		{add, Fun1} ->
			my_handler(Fun1);
		{event, X} ->
			io:fwrite("~s~n", [X]),
			(catch Fun(X)),
			my_handler(Fun)
	end.
	
no_op(_) -> void.